/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.netease.nim.demo.session.viewholder;

import android.text.method.LinkMovementMethod;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.GlideUtil;
import com.netease.nim.demo.NimCache;
import com.netease.nim.demo.session.emoji.MoonUtil;
import com.netease.nim.demo.session.model.MsgListItem;
import com.netease.nim.demo.session.model.extension.ActivityAttachment;
import com.shwread.android.qysw10000227.R;

import java.util.ArrayList;

import logic.bean.NewInteractionInfo;
import logic.util.Utils;

/**
 * @Project： qysw_1.0.8_dev
 * @Title：MsgViewHolderActivityRight
 * @Description：
 * @Author：wayne
 * @Date：2015年5月25日下午8:53:16
 */
public class MsgViewHolderActivityRight
        extends
        MsgViewHolder
{
	private TextView  textViewActivityMessage;
	private ImageView imageViewActivityMessage;
	private ImageView imageViewActivityMessageAtlasIcon;
	
	@Override
    protected int getViewHolderDirection() {
	    return VIEW_HOLDER_RIGHT;
    }

	@Override
    protected int getResId() {
	    return R.layout.activity_message_view_right_item;
    }
	
	@Override
	protected void inflate() {
	    super.inflate();
	    textViewActivityMessage = (TextView) view.findViewById(R.id.textViewActivityMessage);
	    textViewActivityMessage.setMovementMethod(LinkMovementMethod.getInstance());
	    imageViewActivityMessage = (ImageView) view.findViewById(R.id.imageViewActivityMessage);
	    longClickView = textViewActivityMessage;	    
	    imageViewActivityMessageAtlasIcon = (ImageView) view.findViewById(R.id.imageViewActivityMessageatlasIcon);
	}
	
	@Override
	protected void refresh(Object item) {
	    super.refresh(item);
	    ActivityAttachment attachment = (ActivityAttachment) ((MsgListItem)item).getMessage().getAttachment();
	    NewInteractionInfo info =attachment.getInfo();
	    MoonUtil.identifyFaceExpression(NimCache.getContext(), textViewActivityMessage, info.getContent(), ImageSpan.ALIGN_BOTTOM);
	    final String imagelist = info.getImageList();//图片字符串
		if (Utils.isNotEmpty(imagelist))
		{
			String[] strArray = null;
			strArray = imagelist.split(",");
			if (strArray.length == 1)
			{
				//singleInfo.im_atlas.setVisibility(View.GONE);//隐藏图集标注
				imageViewActivityMessageAtlasIcon.setVisibility(View.GONE);
			}
			else
			{
				//singleInfo.im_atlas.setVisibility(View.GONE);//隐藏图集标注
				imageViewActivityMessageAtlasIcon.setVisibility(View.VISIBLE);
			}
			final ArrayList<String> List = new ArrayList<String>();
			for (String url : strArray)
			{
				List.add(url);
			}
			GlideUtil.load(context,strArray[0], imageViewActivityMessage);
			imageViewActivityMessage.setOnClickListener(new OnClickListener()
			{
				
				@Override
				public void onClick(View arg0) {
					eventListener.onAtlasPressed(imagelist);
//					Intent AtlasSeeIntent = new Intent();
//					AtlasSeeIntent.setClass(mContext, NewInteractionAtlasSeeActivity.class);
//					AtlasSeeIntent.putExtra(DefaultConsts.NI_ATLASSEE_URL, List);
//					AtlasSeeIntent.putExtra(DefaultConsts.FROM_TYPE, DefaultConsts.NI_FROM_WEBURL);
//					mContext.startActivity(AtlasSeeIntent);
				}
			});
		}
	}
	
}
